package cn.mengfly.algorithm.collection.bag;

import cn.mengfly.algorithm.collection.stack.LinkedStack;
import cn.mengfly.algorithm.collection.stack.Stack;

import java.util.Iterator;

/**
 * 利用Stack实现背包
 *
 * @param <T>
 */
public class LinkedBag<T> implements Bag<T> {

    private final Stack<T> stack;

    public LinkedBag() {
        this.stack = new LinkedStack<>();
    }

    @Override
    public void add(T t) {
        stack.push(t);
    }

    @Override
    public boolean isEmpty() {
        return stack.isEmpty();
    }

    @Override
    public int size() {
        return stack.size();
    }

    @Override
    public Iterator<T> iterator() {
        return stack.iterator();
    }
}
